[Solved] Not waiting for Xterm to finish , bash script
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
[Solved] Not waiting for Xterm to finish , bash script
Hi doing some bash script and i am using Xterm to execute some scripts .
One of my problems is that when i launch a xterm window from that bash script , the bash script does not continue unless xterm window is finished what is supposed to do .
How to make the bash script continue the instructions and not wait for xterm ?
Quote:
#!/bin/bash
xterm -T "SC1" -geometry 100x10 -e "./script1.sh;bash"
echo "Script 1 was launched"
xterm -T "SC2" -geometry 100x10 -e "./script2.sh;bash"
echo "Script 2 was launched"
echo "all scripts are running"
The problem on the previous code is that the command "echo "Script 1 was launched" will only displayed after xterm finishes script1.sh .
I don't want the bash script to wait for xterm to finish.
I don't know about the scripts that the executed terminals are running but this should work because adding & sends it into its own shell separating it from the parent. ( someone else might be able to put that into words better, but that is the jist of it)
Code:
#!/bin/bash
xterm -T "SC1" -geometry 100x10 -e "./script1.sh;bash" &
echo "Script 1 was launched"
xterm -T "SC2" -geometry 100x10 -e "./script2.sh;bash" &
echo "Script 2 was launched"
echo "all scripts are running"
launch term output
Code:
userx%slackwhere ⚡ testing ⚡> ./launch-eterm
Script 1 was launched
Script 2 was launched
all scripts are running
userx%slackwhere ⚡ testing ⚡>
if it is not working then you/we/someone needs to then look at the other scripts to see what they are doing.
The main bash script have a lot to process , that was an example script .
There should be another way to do it without having to execute 2 commands at same time .
well you lost me there, you have say 2 scripts for some reason you seem to want to use another script to execute a terminal to execute a different script then execute another terminal to execute another script.
that is how it works it is called procedural programing, it runs the first command first when return code gets returned then it runs the next command next.
you'll just have to run them off two separate terminals separately if you want them running simultaneously.
in my testing just now though I did try this
remove the shebang in your 'main script' you are running to get the other two running and see what that does for you, as I created two other scripts to run a for loop to 10 echoing 10 times, it seemed to start faster as a loop count to 10 is really really really fast on my laptop so it is hard to see, after i removed the shebang in the script that fires the other two scripts off.
it did seem to start up more together then the first runs to end before starting the second one.
Code:
uxterm -T "SC1" -geometry 100x10 -e "./echoscript1;bash" &
echo "Script 1 was launched"
uxterm -T "SC2" -geometry 100x10 -e "./echoscript2;bash" &
echo "Script 2 was launched"
echo "all scripts are running"
Eventually if i wanted to use gnome-terminal instead xterm then i do not have this problem .
With gnome terminal i can launch both scripts and the main script will continue its programmed code .
Please explain why do you think you should use any terminal-emulator to execute a program asynchronously?
Because the main bash script is not waiting for any result from the Xterm windows .
Bash script is doing one thing and xterm windows are doing another completely different .
As always , i had to figure out a way to do it .
The solution was to create an independent bash script from the original one with the code to launch only the xterm windows , and that independent bash script will open with gnome terminal .
This way the main script can continue itself .
> > Please explain why do you think you should use any terminal-emulator to execute a program asynchronously?
> Because the main bash script is not waiting for any result from the Xterm windows .
> Bash script is doing one thing and xterm windows are doing another completely different .
This absolutely doesn't answer my question. you can start any number of programs in the background without using any terminal emulators:
Code:
for i in 1 2 3; do
{ echo "$$ start"; sleep 3; echo "$$ end"; } &
done
echo "main program does something else"
wait
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.